Skip to content

fix: use atomic writes for composed preset command files - #3974

Open
Quratulain-bilal wants to merge 3 commits into
github:mainfrom
Quratulain-bilal:fix/presets-composed-file-atomic-write
Open

fix: use atomic writes for composed preset command files#3974
Quratulain-bilal wants to merge 3 commits into
github:mainfrom
Quratulain-bilal:fix/presets-composed-file-atomic-write

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

Problem

Three write_text() calls for composed command files were not atomic. A crash mid-write leaves a partial .md file which can cause errors when the command is later read.

Fix

Now uses a shared _atomic_write_text helper with empfile.mkstemp + os.replace.

Three write_text() calls for composed command files were not atomic.
A crash mid-write leaves a partial .md file which can cause errors
when the command is later read. Now uses a shared _atomic_write_text
helper with tempfile.mkstemp + os.replace.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds atomic writes for composed preset command files to prevent partial files after interrupted writes.

Changes:

  • Adds a shared _atomic_write_text helper.
  • Uses it for all three composed-command write paths.
Show a summary per file
File Description
src/specify_cli/presets/__init__.py Implements and adopts atomic composed-command writes.

Review details

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

try:
with os.fdopen(fd, "w", encoding="utf-8") as f:
f.write(content)
os.replace(tmp, path)
mkstemp() creates files with mode 0600 (owner-only). The original
write_text() used the default umask (typically 0644). Restore the
expected permissions so other users/processes can read the file.
Use os.fchmod() to copy the destination file's permission bits to the
staged temp file when the destination exists. Falls back to mkstemp's
default 0600 when the destination is new.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants